package hk.dao.impl;

import hk.dao.DaoMenu;
import hk.jdbc.DBUtil;
import hk.pojo.MenuInfo;

import java.util.List;

/**
 * @version 1.0
 * @Author YangJiaQuan_hrbnu
 * @Date 2024/4/12 14:18
 */
public class DaoMenuImpl implements DaoMenu {
    @Override
    public List<MenuInfo> getMenuList(int parentId,int roleId) {
        List<MenuInfo> list = DBUtil.getList("select * from menuinfo where parentId = ? and id  in (select menuId from roleMenu  where roleId=?)",MenuInfo.class,parentId,roleId);
        for (MenuInfo menuInfo : list) {
            if(menuInfo.getParentId()==0) {
                menuInfo.setSubMenuList(getMenuList(menuInfo.getId(),roleId));
            }
        }
        return list;
    }
}
